package blog.util.back;

import lombok.Data;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 　　* @description: TODO
 * 　　* @param
 * 　　* @return
 * 　　* @throws
 * 　　* @author Administrator
 * 　　* @date $ $
 *
 */
@Data
public class SensitiveWordFiltering {
    public static String replaceContent(Class aClass,String content) {
        String replaceContent = "";
        try(
                InputStream inputStream = aClass.getClass().newInstance().getClassLoader().getResourceAsStream("mg.properties");
                BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"))
                ) {
            String[] split = br.readLine().split(",");
            for (int i = 0; i < split.length; i++) {
                Pattern r = Pattern.compile(split[i]);
                Matcher m = r.matcher(content);
                if (m.find()) {
                    replaceContent += m.replaceAll("*");
                }
            }
        } catch (IOException ioException) {
            ioException.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
        return replaceContent;
    }
}
